﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;

namespace Flight
{
    public static class Key
    {
        private static HashSet<Keys> prevPressedKeys;
        private static HashSet<Keys> pressedKeys;

        static Key()
        {
            prevPressedKeys = new HashSet<Keys>();
            pressedKeys = new HashSet<Keys>();
        }

        public static bool isPressed(Keys key)
        {
            return pressedKeys.Contains(key);
        }
        public static bool isReleased(Keys key)
        {
            return !isPressed(key);
        }

        public static bool wasPressed(Keys key)
        {
            return pressedKeys.Contains(key) && !prevPressedKeys.Contains(key);
        }
        public static bool wasReleased(Keys key)
        {
            return !pressedKeys.Contains(key) && prevPressedKeys.Contains(key);
        }

        public static void finishFrame()
        {
            prevPressedKeys = pressedKeys;
            pressedKeys = new HashSet<Keys>(Keyboard.GetState().GetPressedKeys());
        }
    }
}
